package exception;

import java.io.FileNotFoundException;

/**
 * @author Huangjin
 * @version 1.0
 * describe:
 * @date 2023/3/9 17:06
 */
public class Student {
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) throws IllegalAgeException {
        if (age <= 0 || age> 100) {
            /*
                当使用throw抛出一个检查异常时，必须在当前方法上使用throws声明该异常的抛出
             */
            throw new IllegalAgeException("年龄不合法！");
        }
        this.age = age;
    }

    public int getAge() {
        return age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
